home *** CD-ROM | disk | FTP | other *** search
/ KeyGen Studio 2002 / KeyGen_Studio_2002.iso / Tutorials / Code Inside / Tut29.txt < prev    next >
Encoding:
Text File  |  2001-09-21  |  8.8 KB  |  220 lines

  1. ************************************************************************************************
  2.                    SantMat's ReverseMe 3
  3. ************************************************************************************************
  4.  
  5. Author:        SantMat
  6. Protection:    None
  7. URL:        http://www.immortaldescendants.org/users/santmat/reversemes/reme3.zip
  8. Tools:        Hex-Editor
  9.  
  10.  
  11. --->    Intro...
  12.  
  13. Welcome to my next Tutorial !!!
  14. This time we need to do the following things:
  15.  
  16. 1.    You must add a new section to the file by way of editing the PE header/Optional Header.
  17. 2.    You must add the message box function to the file by adjusting the import table.
  18. 3.    You must alter the entry point of the file to point to the message box code that is
  19.     within the new section.
  20. 4.     After the execution of the message box, your code must jump back to the original 
  21.     entry point of the file. - So the program can exit nicely using the already imported
  22.     ExitProcess ;)
  23. 5.     IMPORTANT: You are only allowed to change the "PE Header/Optional Header" area of the
  24.     file and the area of the new section you add. You can't change any other sections.
  25.     Especially the import area.
  26. 6.     FINALLY, You are only allowed to use hex/code editors(example: HIEW), you can use
  27.     Wdasm or IDA, but I don't see what good they can do. You are not pe editors like
  28.     procdump or the other numerous ones, or my IID King.
  29. 7.    You must do it all by hand, that is what I am trying to get at here. You must do it
  30.     all manually. No help but your brain and an editor of some kind, for changing the
  31.     hex/code.
  32.  
  33. Ok, So we need to make a Message Box :)
  34. I'm gonna make a Message Box with a question if you're a Lame Reverser :P
  35. If the user presses "Yes" the program jumps to the Original Entry Point and quits.
  36. If the user presses "No" then i'll show another Message Box and then jump and quit :)
  37.  
  38.  
  39. --->    Let's Begin...
  40.  
  41. Ok, well first of all we need to make a new section to add our Code and some Imports stuff.
  42. So open the ReverseMe in your Hex-Editor.
  43. Then look at the PE Header, we got 3 sections namely:
  44.  
  45. .text
  46. .rdata
  47. .data
  48.  
  49. To make a new section we need to well add a new section :) and change the number of sections
  50. located 6 bytes after where the PE Header starts.
  51. So first change this for the section number:
  52.  
  53. offset 000000B0        50 45 00 00 4C 01 03 00
  54.  
  55. to
  56.  
  57. offset 000000B0        50 45 00 00 4C 01 04 00
  58.  
  59. Ok then get to the last section (called .data) to add our new section.
  60. A section is made out of this:
  61.  
  62. Section Name        2 dwords
  63. Raw Length        dword
  64. Virtual Address        dword
  65. Virtual Length        dword
  66. Raw Address        dword
  67. ?            dword
  68. ?            dword
  69. ?            dword
  70. Flags            dword
  71.  
  72. So right behind the other section (at offset 00000220) we put our new Section Name i've used:
  73.  
  74. InSiDe
  75.  
  76. You can type whatever you want there as long as it's 8 bytes :)
  77.  
  78. Then at offset 00000228 we put our "Raw Length" we'll make it 00000100 that's enough :)
  79.  
  80. Then at offset 0000022C we put our "Virtual Address" look at the previous section to see what's
  81. the "Virtual Address" there, it's 00003000 so just add 00001000 to it (look for the value next
  82. to it, it's 00000200 so we're ok, otherwise we need to add more then 00001000 :) so enter at our
  83. section 00004000.
  84.  
  85. Then at offset 00000230 we put our "Virtual Length" we'll just make it 00001000 big enough ;)
  86.  
  87. Then at offset 00000234 we put our "Raw Address" look at the bottom of the file it ends at offset
  88. 000009FF so our new section starts at 00000A00 :) so enter as value 00000A00.
  89.  
  90. Then at offset 00000244 we put our "Flags" well just make it 200000E0 :)
  91.  
  92. So now we got this:
  93.  
  94. offset 00000220        Section Name        496E536944650000 (InSiDe)
  95. offset 00000228        Raw Length        00000100
  96. offset 0000022C        Virtual Address        00004000
  97. offset 00000230        Virtual Length        00001000
  98. offset 00000234        Raw Address        00000A00
  99. offset 00000238        ?            00000000
  100. offset 0000023C        ?            00000000
  101. offset 00000240        ?            00000000
  102. offset 00000244        Flags            200000E0
  103.  
  104. Ok, now we made our new section :) but there's one more thing we need to change in the PE Header.
  105. We need to point the Import Table to our Section (to Import MessageBoxA).
  106. We can find the "Virtual Address" at offset 00000130 change it into 00004000.
  107. Now we need to add some bytes, go to the end of the file and add 100 bytes (beginning from offset
  108. 00000A00).
  109. Btw, we need to change the Entry Point later because we don't know yet where it starts :)
  110.  
  111. Now we need to make the Import Table starting at offset 00000A00.
  112. The Import Table structure looks like this:
  113.  
  114. OriginalFirstThunk    dword
  115. TimeDateStamp        dword
  116. ForwarderChain        dword
  117. Name            dword
  118. FirstThunk        dword
  119.  
  120. I'll tell the values immediately otherwise i need to come back everytime to tell it :)
  121. Ok, we need to make 2 of those structures (one for the allready defined ExitProcess, and one for
  122. our MessageBoxA) because we got 2 different .dll's "kernel32.dll and user32.dll".
  123. So first the "OriginalFirstThunk" this one doesn't has to be specified so leave it empty :)
  124. Then the "TimeDateStamp" this one we can also leave empty (it'll be replaced when executed)
  125. Then the "ForwarderChain" also this one empty (it'll be replaced when executed)
  126. Then the "Name" this points to the .dll name (this one is for ExitProcess "kernel32.dll") so
  127. enter 00002046
  128. Then we get the "FirstThunk" that points to an RVA that points to the ExitProcess API it's
  129. 00002000
  130.  
  131. So now we got this for the ExitProcess API:
  132.  
  133. offset 00000A00        00000000
  134. offset 00000A04        00000000
  135. offset 00000A08        00000000
  136. offset 00000A0C        00002046
  137. offset 00000A10        00002000
  138.  
  139. Now the next structure right behind it, i'll show you immediately:
  140.  
  141. offset 00000A14        00000000
  142. offset 00000A18        00000000
  143. offset 00000A1C        00000000
  144. offset 00000A20        0000404C
  145. offset 00000A24        00004038
  146.  
  147. Now we leave 10 bytes empty, so it recognizes that these structures has ended :)
  148. then we enter at offset 00000A38, 0000403E (this points to our MessageBoxA).
  149. Ok well let me show you what we got so far :)
  150.  
  151. offset 00000A00        00 00 00 00 00 00 00 00 00 00 00 00 46 20 00 00
  152. offset 00000A10        00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  153. offset 00000A20        4C 40 00 00 38 40 00 00 00 00 00 00 00 00 00 00
  154. offset 00000A30        00 00 00 00 00 00 00 00 3E 40 00 00 00 00 00 00
  155. offset 00000A40        4D 65 73 73 61 67 65 42 6F 78 41 00 75 73 65 72
  156. offset 00000A50        33 32 2E 64 6C 6C 00 00 00 00 00 00 00 00 00 00
  157. offset 00000A60        00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  158.  
  159. Ok, Import Table completed :) on to the Message Box stuff...
  160. First of all i'm going to add the text "I am a LaMe rEvErSeR! :P" at offset 00000A70
  161. (followed by a 00 character).
  162. Remember that i said i wanted to make some sort of question thingy :) so behind this string i'll
  163. add the string "Question" (followed by a 00 character,this will be the title of the Message Box).
  164. And now one more string for the second Message Box, let's put this string "Liar !!! :P" ;)
  165. (followed by a 00 character).
  166. So now we got this:
  167.  
  168. offset 00000A70        49 20 61 6D 20 61 20 4C 61 4D 65 20 72 45 76 45
  169. offset 00000A80        72 53 65 52 21 20 3A 50 00 51 75 65 73 74 69 6F
  170. offset 00000A90        6E 00 4C 69 61 72 20 21 21 21 20 3A 50 00 00 00
  171.  
  172. Now we can begin with coding :) and we know now also the Entry Point so you can change that
  173. aswell in the PE Header at offset 000000D8, enter their 000040A0.
  174. Ok, the Message Box procedure starts at offset 00000AA0, Code it in the way you want :)
  175. I've got this:
  176.  
  177. Push 00000004            = For the "Yes , No" Procedure
  178. Push 00404089            = Title of the Message Box "Question".
  179. Push 00404070            = Text on the Message Box "I am a LaMe rEvErSeR! :P".
  180. Push 00000000            = We don't have a main window or something so just push 00 ;)
  181. Call [MessageBoxA]        = Call the Message Box.
  182. Cmp eax, 00000007        = Compare EAX with 07 (has the user clicked "No"? )
  183. je 004040BF            = If equal jump to the next Message Box
  184. Push 00401000            = Push the offset to the original Code.
  185. ret                = go to it.
  186. Push 00000000            = Push 00 for a standard Message Box (just an "Ok" button)
  187. Push 00404089            = Title of the Message Box "Question".
  188. Push 00404092            = Text on the Message Box "Liar !!! :P".
  189. Push 00000000            = We don't have a main window or something so just push 00 ;)
  190. Call [MessageBoxA]        = Call the Message Box.
  191. Push 00401000            = Push the offset to the original Code.
  192. ret                = go to it.
  193.  
  194. hehe, noticed the places that returns to the ExitProcess, i could use jumps but nah... ;)
  195. Ok well, that's all save the file and run it, it works !!! ;P
  196.  
  197.  
  198. --->    Outro...
  199.  
  200. Well, nice ReverseMe, i like such ReverseMes... dunno why ;)
  201. I hope i explained it very well, if you have question, just something to say or whatever
  202. mail me :P
  203.  
  204. Email:    code.inside@home.nl
  205.  
  206.  
  207. --->    Greetings...
  208.  
  209. To be honest i'm getting a bit sick of these greetings everytime ;P
  210. So i'll just say:
  211.  
  212. Greetings to everyone i know, and to everyone who knows me, and You... ;P
  213.  
  214.  
  215.             Don't trust the Outside, trust the InSiDe !!!
  216.  
  217.                       Cya...
  218.  
  219.                     CoDe_InSiDe
  220.